<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | create by allen.qiang
// +----------------------------------------------------------------------


/**
 * 刮刮卡操作功能
 * @package  htdocs
 * @subpackage  quanliadmin
 * @create by allen.qiang
 */
quanli_require('module/base/promotionHandler.class.php');
class pa_scratch {

    public function execute() {

        if (isset($_REQUEST['operFlg']) && is_numeric($_REQUEST['operFlg']) && $_REQUEST['operFlg'] > 0) {

            switch ($_REQUEST['operFlg']){
                case 1: //微信互动活动列表
                    $this->scratchList();
                    break;
                case 2: //微信互动活动添加
                    $this->scratchAdd();
                    break;
                default:
                    $this->toError('参数错误');
                    break;
            }

        } else {

            $this->toError('参数错误');

        }

    }

    /**
     * 转跳到错误页面
     * @param string $msg 错误信息
     */
    private function toError( $msg = '' ) {

        global $G_PGLOB;

        $G_PGLOB->display_error_page( $msg );

    }

    /**
     * 刮刮卡列表
     */
    private function scratchList() {

        global $G_PGLOB;

        $edit_permission = $G_PGLOB->has_permission(4521);

        $G_PGLOB->smarty->assign('edit_permission',$edit_permission);

        $G_PGLOB->smarty->display('promotion/scratchList.tpl');

    }

    /**
     *微信互动活动添加
     */
    private function scratchAdd(){

        global $G_PGLOB;

        //编辑
        if(isset($_REQUEST['promotionID'])){

            $time = date('Y-m-d H:i:s');

            $promotionHandler = new promotionHandler($G_PGLOB->DBCA);

            $arg_array = $_REQUEST;

            $promotion = $promotionHandler->searchWxActivity($arg_array);

             //判断当前是否在活动时间内
            $starttotime = $promotion[0]['startDate'].' 00:00:00';

            $endtotime = $promotion[0]['endDate'].' 23:59:59';

            if($time>=$starttotime && $time<=$endtotime){
                $this->toError('当前正在活动期间内，禁止修改该活动');
            }

            $promotion_detail = $promotionHandler->searchWxActivityDetail($arg_array);

            $G_PGLOB->smarty->assign('promotionID',$_REQUEST['promotionID']);
            $G_PGLOB->smarty->assign_by_ref('promotion',$promotion);
            $G_PGLOB->smarty->assign_by_ref('promotion_detail',$promotion_detail);


        }

        $G_PGLOB->smarty->display('promotion/scratchEdit.tpl');

    }

}